package org.grow.webchat.chat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;

@RestController
public class NoticePush {
    @Autowired
    SimpMessagingTemplate messagingTemplate;
    @GetMapping("/pushnotice")
    public Boolean push(@RequestParam String msg){
        try {
        HashMap<String, Object> notice = new HashMap<>();
        notice.put("from","张三丰");
//        操作人可以通过ｃｏｎｔｅｘｔｈｏｌｄｅｒ获取
        notice.put("core",msg);
        notice.put("time", LocalDateTime.now());
        messagingTemplate.convertAndSend(
                ChatBrokerConfig.BrokerNotice+"/common",
                notice);
        }catch (Exception e){
            return false;
        }
        return true;
    }

}
